import React, { Component } from 'react'
import Search from './components/Search'
import List from './components/List'
import './App.css'

export default class App extends Component {
  // 初始化状态
  state = {
    users: [], // user初始值为数组
    isFirst: true, // 是否第一次打开页面
    isLoading: false, // 标识是否处于加载中
    err: '', // 存储请求相关的错误信息
  }

  updateAppState = (stateObj) => {
    this.setState(stateObj)
  }

  // 保存用户
  saveUsers = (users) => {
    this.setState({users})
  }
  render() {
    const {users} = this.state
    return (
      <div>
        <div className="container">
          <Search updateAppState={this.updateAppState}/>
          <List {...this.state} users={users} />
        </div>
      </div>
    )
  }
}
